package cn.caplike.demo.spring.bean.lifecycle.initializing.bean.and.disposable.bean.callback.interfaces;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

/**
 * Description:
 *
 * @author LiKe
 * @date 2020-03-31 17:29:58
 */
@Component
public class Book implements
        /*
         * Declares the afterPropertiesSet() method which can be used to write the initialization logic.
         * The container calls the method after properties are set.
         */
        InitializingBean,
        /*
         * Declares the destroy() method which can be used to write any cleanup code.
         * The container calls this method during bean destruction in shutdown.
         */
        DisposableBean {
    private String bookName;

    public Book() {
        System.out.println("Constructor of Book bean is called !! ");
    }

    public Book(String bookName) {
        this.bookName = bookName;
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("Destroy method of Book bean called !! ");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("afterPropertiesSet method of Book bean is called !! ");
    }

    public String getBookName() {
        return bookName;
    }

    public void setBookName(String bookName) {
        this.bookName = bookName;
    }

    @Override
    public String toString() {
        return "Book{" +
                "bookName='" + bookName + '\'' +
                '}';
    }
}
